//
//  BaseModel.m
//  classicFilms
//
//  Created by 刘继丹 on 17/4/26.
//  Copyright © 2017年 Stefan Arn. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel

+ (void)startMonitoringNetworkStatus{
    AFNetworkReachabilityManager *reachabilityManager = [AFNetworkReachabilityManager sharedManager];
    [reachabilityManager startMonitoring];
    [reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch ((NSInteger)status) {
            case AFNetworkReachabilityStatusNotReachable:{
                NSLog(@"网络连接中断");
                
                [[NSNotificationCenter defaultCenter] postNotificationName:@"noHaveNetworking" object:self userInfo:nil];
                
                break;
            }
            case AFNetworkReachabilityStatusUnknown:{
                NSLog(@"网络连接中断");
                
                [[NSNotificationCenter defaultCenter] postNotificationName:@"noHaveNetworking" object:self userInfo:nil];
                
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWiFi:{
                NSLog(@"当前WiFi网络");
                
                [[NSNotificationCenter defaultCenter] postNotificationName:@"haveNetworking" object:self userInfo:nil];
                
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWWAN:{
                NSLog(@"当前3G网络");
                
                [[NSNotificationCenter defaultCenter] postNotificationName:@"haveNetworking" object:self userInfo:nil];
                
                break;
            }
        }
    }];
}

//返回网络状态
+ (AFNetworkReachabilityStatus)networkReachabilityStatus{
    return [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus;
}

+(BOOL)isHaveNetworking{
    if ([BaseModel networkReachabilityStatus] == AFNetworkReachabilityStatusReachableViaWiFi || [BaseModel networkReachabilityStatus] == AFNetworkReachabilityStatusReachableViaWWAN  ) {
        return YES;
    }else{
        return NO;
    }
}


@end
